package com.oe.rpc.spring;

import com.oe.rpc.context.LdmRpcEventProcessor;
import com.oe.rpc.context.RpcContext;
import com.oe.rpc.core.RpcCore;
import com.oe.rpc.core.events.TryConnectEvent;
import com.oe.rpc.core.model.RpcConsumer;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class LdmConsumerBean extends RpcConsumer implements InitializingBean,FactoryBean, DisposableBean {

    @Override
    public Object getObject() throws Exception {
        Object o = RpcCore.newInstance().proxyConsumer(this);
        RpcContext.getInstance().cacheConsumerConfig(this.getInterfaceClass().getName(),this);
        return o;
    }

    @Override
    public Class<?> getObjectType() {
        return this.getInterfaceClass();
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    @Override
    public void destroy() throws Exception {

    }

    //尝试从注册中心获取服务列表
    @Override
    public void afterPropertiesSet() throws Exception {
        RpcContext.getInstance().getRegisterHolder().center().list(this.getInterfaceClass().getName());
    }

}
